﻿using DSFramework;
using UnityEngine;

public static class UnityTool
{
    /// <summary>
    /// 查找子物体
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="childName"></param>
    /// <returns></returns>
    public static GameObject FindChild(GameObject parent, string childName)
    {
        Transform[] children = parent.GetComponentsInChildren<Transform>();
        bool isFinish = false;
        GameObject child = null;
        foreach (var trans in children)
        {
            if (trans.name.Equals(childName))
            {
                if (isFinish)
                {
                    Debug.LogWarning($"在游戏物体{parent}下存在不止一个物体{childName}");
                }

                isFinish = true;
                child = trans.gameObject;
            }
        }

        return child;
    }

    public static void Attack(GameObject parent, GameObject child)
    {
        child.SetParent(parent);
        child.ReSetLocalPos();
        child.ReSetLocalScale();
        child.ReSetLocalEulerAngles();
    }
}